<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<style>
    .form-group > label {
        width: 60px;
    }
</style>
<script type="text/javascript">
    var menuids =${sessionScope.menus_session_key}+",";
    var archives = {
        searchFormCallback: function (json) {
            console.log(json);
            if (json.code == 0) {
                var page = json.data;
                if (page.rows.length < 1) {
                    $(this).alertmsg('info', "无数据");
                }
                archives.showGridData(page, 'O');
            } else {
                $(this).alertmsg('error', json.msg);
            }
        },
        showGridData: function (page, domainNo) {
            var pageNum = page.currPage;//当前页页码
            var pageSize = page.pageSize;//每页多少条
            var size = page.size;//当前页有多少条
            var total = page.total;//总条数
            var pages = page.pages;//总页数
            var list = page.rows;

            var trs = "";

            var tempCount = '<tr><td>{tp0}</td><td>{tp1}</td><td>{tp2}</td><td>{tp3}</td><td>{tp4}</td></tr>';

            for (var i = 0; list != null && i < list.length; i++) {
                var operation = '';
                if (menuids.indexOf(",55,") > -1) {
                    operation = operation + '<a class="btn btn-blue" data-icon="info" data-title="查看--' + list[i].name + '" data-height="1000" data-width="750" data-mask="true" data-toggle="dialog" href="filesupload/wordshow/' + list[i].fileNo + '.shtml">预览</a>';
                }
                if (menuids.indexOf(",56,") > -1) {
                    operation = operation + '&nbsp;<a class="btn btn-green" data-icon="sign-out"  href="filesupload/word/download/' + list[i].fileNo + '.shtml">下载</a>';
                }
                if (menuids.indexOf(",57,") > -1) {
                    operation = operation + '&nbsp;<a	class="btn btn-red" data-icon="minus" data-mask="true" data-toggle="doajax" data-confirm-msg="请确认是否删除此档案？" data-callback="doAjaxCallBack"  href="document/archives/delete/' + list[i].id + '.shtml">删除</a>';
                }

                var tempStr = tempCount
                    .replace("{tp0}", (i + 1))
                    .replace("{tp1}", list[i].name)
                    .replace("{tp2}", list[i].creator)
                    .replace("{tp3}", list[i].creatTime)
                    .replace("{tp4}", operation);

                trs += tempStr;

                $.CurrentNavtab.find("#archiveslist").html("");
                $.CurrentNavtab.find("#archiveslist").append(trs);

            }

            $.CurrentNavtab.find("th").css("text-align", "center");
            $.CurrentNavtab.find("td").css("text-align", "center");
            $.CurrentNavtab.find("#total").html(total);
            refreshPageBar(total, pageNum, pageSize);
        }
    };

    $(function () {
        var page = ${page};
        archives.showGridData(page, 'O');

        //查询提交按钮事件
        $.CurrentNavtab.find("#queryform").on("click", function () {
            var archivesname = $.CurrentNavtab.find("#archivesname").val();
            var creatTime = $.CurrentNavtab.find("#creatTime").val();
            var criterias = [];
            if (!Dracula.util.isEmpty(creatTime)) {
                criterias.push({
                    field: 'creatTime',
                    condition: "like",
                    value: creatTime + "%"
                });
            }
            if (!Dracula.util.isEmpty(archivesname)) {
                criterias.push({
                    field: 'name',
                    condition: "like",
                    value: archivesname + "%"
                });
            }
            var formQuery = {
                currPage: parseInt($.CurrentNavtab.find("#pagerForm > input[name=pageNum]").val()),
                pageSize: parseInt($.CurrentNavtab.find("#pagerForm > input[name=pageSize]").val()),
                criterias: criterias,
                entity: 'business.Archives'
            };
            Dracula.post('query.shtml', formQuery, archives.searchFormCallback);
        });

        $.CurrentNavtab.find("#fileUpload").upload({
            uploader: "filesupload/uploadify/document/Archives.shtml",
            fileSizeLimit: 1024,
            buttonText: "点击上传新档案",
            fileTypeExts: "*.doc;*.docx",
            icon: "cloud-upload",
            onUploadSuccess: "fileUploadSuccess",
            multi: "true",
            previewImg: false,
            dragDrop: true
        });

    });

    /***
     * 文件上传回调
     */
    function fileUploadSuccess(file, data, $element) {
        var json = $.parseJSON(data);
        if (json.code != 0) {
            $(this).alertmsg('error', json.msg);
            return;
        }
        var file = json.data;
        var filename = file.name;
        $(this).alertmsg('ok', '' + filename + '上传成功');
        $.CurrentNavtab.find("#queryform").click();
    }

</script>

<%--查询表单--%>
<div class="bjui-pageHeader"
     style="height: auto; padding-top: 10px; padding-bottom: 10px;">
    <form id="pagerForm" class="pageForm" data-toggle="ajaxsearch" method="post">
        <input type="hidden" id="pageSize" name="pageSize" value="15">
        <input type="hidden" id="pageNum" name="pageNum" value="1">
        <input type="hidden" id="totalsize" name="totalsize">
        <div class="bjui-searchBar" style="z-index: 100">
            <div class="row">
                <div class="col-md-4">
                    <div class="form-group">
                        <label>创建年份：</label>
                        <input type="text" data-pattern="yyyy-MM"
                               id="creatTime" name="creatTime" data-toggle="datepicker" data-max-date="%y-%M"
                               class="form-control"/>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>档案名称：</label>
                        <input type="text" id="archivesname" name="archivesname" class="form-control"/>
                    </div>
                </div>
                <div class="col-md-8" style="margin-left: 300px">
                    <div class="form-group " style="float: left">
                        <button id="queryform" class="btn-primary" data-icon="search">查询</button>
                        &nbsp; <a class="btn btn-orange" href="javascript:;"
                                  onclick="resetFormAndSearch()" data-icon="undo">清空查询</a>&nbsp;&nbsp;&nbsp;&nbsp;

                        <c:if test="${fn:contains(sessionScope.menus_session_key,',54,')}">
                            <div id="fileUpload" data-toggle="upload" style="z-index: 101;display: inline;"></div>
                            <span style="color: #BFBFBF;display: inline;">文件类型可为docx、doc,大小不超过1M,文件名不超过40个字。</span>
                        </c:if>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <br>
    <br>
    <br>
    <br>
    <br>
</div>

<%--信息表格--%>
<div class="bjui-pageContent tableContent" id="contentList" style="z-index: 2">
    <table data-toggle="tablefixed" data-width="100%" data-nowrap="true" id="archivestable" style="z-index: 2">
        <thead>
        <tr id="archivestr">
            <th width="40">编号 <br></th>
            <th width="120">档案名称<br></th>
            <th width="120">创建人<br></th>
            <th width="120">创建时间<br></th>
            <th width="200">操作<br></th>
        </tr>
        </thead>
        <tbody id="archiveslist">
        </tbody>
    </table>
</div>
<%--分页信息栏--%>
<div class="bjui-pageFooter">
    <div style="height: 32px">
        <ul class="pagination" style="margin: 0;padding:0;float: right">
            <li><span>共 <span id="total">0</span>条
		</span></li>
            <li><span>共 <span id="pageNunmber">0</span>页
		</span></li>
            <li class="j-first">
                <a class="first" href="javascript:page.first();"><i class="fa fa-step-backward"></i> 首页</a>
            </li>
            <li class="j-prev">
                <a class="previous" href="javascript:page.pre();"><i class="fa fa-backward"></i> 上一页</a>
            </li>
            <li class="j-prev">
                <a class="previous" href="javascript:;"><span id="currentPage"></span></a>
            </li>
            <li class="j-next">
                <a class="next" href="javascript:page.next();">下一页 <i class="fa fa-forward"></i></a>
            </li>
            <li class="j-last">
                <a class="last" href="javascript:page.last();">末页 <i class="fa fa-step-forward"></i></a>
            </li>
            <li><span style="padding: 2.5px;"><input type="text" id="selfpagenum" size="3" value="1"
                                                     style="text-align: center;padding: 3px"></span><a class="goto"
                                                                                                       href="javascript:page.goto();"
                                                                                                       title="GO">GO</a>
            </li>

        </ul>
    </div>
</div>
